<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> XX影院电影管理
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="container">
            <div class="handle-box">
                <el-form :model="query" :inline="true">
                    <el-form-item label="电影名:">
                        <el-input v-model="query.name"  class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="电影类型:">
                        <el-select v-model="query.type" class="handle-select mr10">
                            <el-option v-for="(item,index) in types" :key="index" :value="item.typename">
                                {{item.typename}}
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="handleBtnQuery()">搜索</el-button>
                    </el-form-item>
                </el-form>

                <el-button
                        type="primary"
                        icon="el-icon-plus"
                        class="handle-select"
                        @click="handleadd()"
                >添加库存电影</el-button>
                <el-button
                        type="warning"
                        icon="el-icon-edit"
                        class="handle-select"
                        @click="handleedit()"
                >修改电影</el-button>
                <el-button
                        type="danger"
                        icon="el-icon-delete"
                        class="handle-del mr10"
                        @click="updateStatus()"
                >撤档电影</el-button>
                <el-button
                        type="primary"
                        icon="el-icon-refresh"
                        class="handle-select"
                        @click="handlerefresh()"
                >刷新列表</el-button>
            </div>

            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="moviedetailsid" label="ID" width="55" align="center"></el-table-column>
                <el-table-column prop="moviechinesename" label="电影名" align="center"></el-table-column>
                <el-table-column prop="movieorigin" label="产地" align="center"></el-table-column>
                <el-table-column prop="movieduration" label="影片时长" align="center"></el-table-column>
                <el-table-column prop="movieduration" label="影片票房" align="center"></el-table-column>
                <el-table-column prop="exceptedcount" label="热度值" align="center"></el-table-column>
                <el-table-column prop="reputation" label="口碑评分"></el-table-column>
                <el-table-column prop="moviestatus" label="状态" align="center"></el-table-column>

                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleschedlue(scope.$index,scope.row)"
                        >排片</el-button>
                        <el-button
                                 type="text"
                                icon="el-icon-document"
                                class="active"
                                @click="showMoviedetails(scope.$index,scope.row)"
                        >详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="query.currentPage"
                        :page-sizes="[15, 30, 50, 100]"
                        :page-size="query.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="currentTotal"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="库存电影" :visible.sync="addVisible" width="30%">


        </el-dialog>
    </div>
</template>

<script>
import { fetchData } from '../../api/index';
export default {
    name: 'Query_the_film_cinema.vue',
    data() {
        return {
            query: {
                type: '',
                name: '',
                pageIndex: '',
                pageSize: 10
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            addVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            fetchData(this.query).then(res => {
                console.log(res);
                this.tableData = res.list;
                this.pageTotal = res.pageTotal || 50;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.tableData.splice(index, 1);
                })
                .catch(() => {});
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
